/**
 * @file       Panel.h
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef PANEL_H_
#define PANEL_H_

#include <vector>
#include <map>
#include "Frame.h"
#include "PageInfo.h"
#include "errorcode.h"

namespace NS_LCD_AFW
{

class CContext;
class CPagingStrategy;

class CPanel: public CFrame
{
public:
	CPanel();
protected:
	virtual ~CPanel();
public:
	virtual int add(CFrame *pFrame);
	virtual int remove(CFrame *pFrame);
	virtual CFrame * getChild(const std::string & strName);
	CFrame *getFocusObject() const;
	CFrame *setFocusObject(CFrame *pFrame);

protected:
	const CFramePtrArray & getChildFrameArray() const;
	void setPagingStrategy(CPagingStrategy *pStrategy);
	CPageInfo & getPageInfo();
public:

protected:
	void cleanChildObject();

	//calculate according to the device width and height as the area
	int calculateViewPort();

	int calculatePaging();

	void close(int exitCode = ERR_SUCCESS);

public:
	virtual int handler(IEvent *pEvent);
protected:

	virtual int onCreate();
	virtual int onClose();
	virtual int onDraw(IDisplay *pDisplay);
	virtual void preCreate();
	virtual void preShow();
	virtual void onSetFocus();
	virtual void onLostFocus();
	virtual void onSize(const CRect &oldRect, const CRect &newRect);
	virtual void onVisible();
	virtual void onInvisible();

protected:
	virtual int onEscKeyPress();
	virtual int onEnterKeyPress();
protected:
	virtual void onHightlight();
	virtual void onUnHightlight();
	virtual int onRightKeyPress();
	virtual int onLeftKeyPress();
	virtual int onUpKeyPress();
	virtual int onDownKeyPress();

private:
	CFrame * m_pFocusFrame;
	CPagingStrategy *m_pPagingStrategy;
	CFramePtrArray m_framePtrArray;
	CPageInfo m_pageInfo;

private:
	static bool sortFrameArray(CFrame *p1, CFrame *p2);

private:
	DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(CPanel);

};

} /* namespace NS_LCD_AFW */
#endif /* PANEL_H_ */
